<template>
  <!--CA绑定弹框-->
  <Modal v-model="modalShow" :loading="modalLoading" :title="admin.nickName + 'CA账号'" ok-text="解绑" @on-ok="okModal" @on-cancel="cancelModal">
    <Form :label-width="100">
      <FormItem label="用户证书标识">
        <Input :value="admin.caOid" readonly placeholder="用户证书标识"></Input>
      </FormItem>
      <FormItem label="电子签章">
        <img v-if="admin.caSignature" :src="'data:image/png;base64,'+admin.caSignature" />
        <template v-else>-</template>
      </FormItem>
    </Form>
    
    
    <Spin v-if="loading" size="small" fix></Spin>
  </Modal>
</template>

<script>
import api from "@/api/commonApi";

export default {
  name: 'UnBindCaModalCom',
  emits: ['success'],
  data() {
    return {
      loading: false,
      modalLoading: true,
      modalShow: false,

      admin: {},
      
      userCertUid: '',
      currentUserPicture: '',
    }
  },
  methods: {
    init(){
      this.loading = false
      this.modalLoading = true

      this.admin = {}
      
      this.userCertUid = ''
      this.currentUserPicture = ''
    },
    show(payload) {
      this.init()

      this.loading = true
      
      this.admin = JSON.parse(JSON.stringify(payload))
      
      if(this.admin.prescriptionSignature) {
        this.admin.prescriptionSignature = JSON.parse(this.admin.prescriptionSignature)
      }

      this.modalShow = true

      this.loading = false
    },
    okModal() {
      
      if(!this.admin.id){
        this.$Message.warning('账号用户ID不能为空')
        this.modalLoading = false
        setTimeout(() => {
          this.modalLoading = true
        },500)
        return
      }

      this.$Modal.confirm({
        title: '解绑CA账号',
        content: '<p>是否确认解绑该CA账号？</p>',
        onOk: () => {
          this.$axios
          .post(api.caManageUnBind+'/'+this.admin.id, {}).then(res=>{
            this.modalShow = false
            this.$emit('success')
          })
        },
        onCancel: () => {
          this.modalLoading = false
          setTimeout(() => {
            this.modalLoading = true
          },500)
        }
      });
      
    },
    cancelModal() {
      this.modalShow = false
    }
  }
};
</script>

<style lang="less" scoped>
/deep/ .ivu-modal-wrap {
  .ivu-modal{
    float: none !important;
    top: 100px !important;
    height: auto !important;
  }
}
</style>